//
//  OrderProductCell.m
//  GasCome
//
//  Created by zfc on 2020/5/9.
//  Copyright © 2020 zfc. All rights reserved.
//

#import "OrderProductCell.h"

@interface OrderProductCell ()

@property (nonatomic, strong) UIImageView *imgV;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UILabel *descLab;
@property (nonatomic, strong) UILabel *countLab;

@end

@implementation OrderProductCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setUI {

    self.imgV = [[UIImageView alloc] init];
    self.imgV.backgroundColor = ColorF5;
    [self.contentView addSubview:self.imgV];
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(8);
        make.leading.equalTo(self.contentView).offset(15);
        make.height.width.mas_equalTo(40);
    }];

    

    self.descLab = [[UILabel alloc] init];
    self.descLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    self.descLab.textColor = Color999;
    [self.contentView addSubview:self.descLab];
    [self.descLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imgV);
        make.leading.equalTo(self.imgV.mas_trailing).offset(10);
    }];

    self.priceLab = [[UILabel alloc] init];
    self.priceLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    self.priceLab.textColor = Color333;
    self.priceLab.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.priceLab];
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgV);
        make.trailing.equalTo(self.contentView).offset(-15);
//        make.leading.equalTo(self.titleLab.mas_trailing).offset(10);
    }];
    
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    self.titleLab.textColor = Color333;
    [self.contentView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgV);
        make.leading.equalTo(self.imgV.mas_trailing).offset(10);
        make.trailing.equalTo(self.priceLab.mas_leading).offset(-10);

    }];
    


//
    [self.titleLab setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
    [self.priceLab setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
    
    self.countLab = [[UILabel alloc] init];
    self.countLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    self.countLab.textColor = Color999;
    [self addSubview:self.countLab];
    [self.countLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imgV);
        make.trailing.equalTo(self).offset(-15);
    }];

}

- (void)setProductDic:(NSDictionary *)productDic {
    _productDic = productDic;

    [self.imgV sd_setImageWithURL:[NSURL URLWithString:productDic[@"product_picture"]]];
    
    [self.imgV sd_setImageWithURL:[NSURL URLWithString:productDic[@"product_picture"]] placeholderImage:[UIImage imageNamed:@"5KG"]];
    self.countLab.text = [NSString stringWithFormat:@"x%@", productDic[@"num"]];
    
    
    self.titleLab.text = productDic[@"product_name"];

    
    if ([productDic[@"order_type"] integerValue] == 9) {
        self.descLab.text = [NSString stringWithFormat:@"%@;%@", productDic[@"subjoin_delivery"], productDic[@"subjoin_service"]];
        self.priceLab.text = [NSString stringWithFormat:@"¥%.2f", ([productDic[@"price"] floatValue]  + [productDic[@"subjoin_service_money"] floatValue])];
    } else {
        self.descLab.text = productDic[@"sku_name"];
        self.priceLab.text = productDic[@"product_money"];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
